﻿using System;
using System.Collections.Generic;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
using System.Windows;
using Xceed.Wpf.DataGrid;

namespace Kinlo.UI.Main
{
    /// <summary>
    /// App.xaml 的交互逻辑
    /// </summary>
    public partial class App : Application
    {
        Mutex mutex;
        protected override void OnStartup(StartupEventArgs e)
        {
            //// 添加全局异常处理器
            //AppDomain.CurrentDomain.UnhandledException += (sender, args) =>
            //{
            //    Exception ex = (Exception)args.ExceptionObject;
            //    // 这里可以替换为你的日志记录方法
            //    Console.WriteLine($"未处理的异常： {ex.Message}");
            //};

            //DispatcherUnhandledException += App_DispatcherUnhandledException;

            bool testResult = false;
            mutex = new Mutex(true, "KINLO", out testResult);
            if (testResult)
            {
                base.OnStartup(e);
            }
            else
            {
                MessageBox.Show("程序已运行,请勿重复运行", "错误", MessageBoxButton.OK, MessageBoxImage.Error);
                Environment.Exit(0);
                return;
            }
        }

        //void App_DispatcherUnhandledException(object sender, System.Windows.Threading.DispatcherUnhandledExceptionEventArgs e)
        //{
        //    //e.Exception   发生的异常
        //    //e.Handled	 是否已处理异常事件
        //    //DataLog.SaveLog("程序异常：" + e.Exception.Source + "@@" + e.Exception.Message);
        //    MessageBox.Show("程序异常：" + e.Exception.Source + "@@", "错误", MessageBoxButton.OK, MessageBoxImage.Error);
        //}
    }


}
